package full

import (
	"db2s/ETL"
	"db2s/global"
	"db2s/parDef"
	"db2s/ref"
)

func (fu Full) sumEr(drive string) (ter SumEr, err error) {
	if ter, err = NewFullSum(drive); err != nil {
		err = ref.ErrAddPrintf("Full.sumEr", err)
		return
	}
	return
}

var ExternalCallAnyToInt64Func = func(s any, _ any) (res any, err error) {
	return ref.StringAnyToInt64(s)
}
var ExternalCallAnyToFloat64Func = func(s any, _ any) (res any, err error) {
	return ref.StringAnyToFloat64(s)
}

func (fu Full) rowsSize() (meta any, err error) {
	var ter SumEr
	if meta, err = parDef.CallMethod(fu.Drive, fu.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = fu.sumEr(v); err != nil {
			return
		}
		if result, err = ter.Rows(parDef.CtxBackground(parDef.GeneralReadMethodParameter(fu.Parameter1[k], ExternalCallAnyToInt64Func, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("rowsSize", err)
		return
	}
	return
}
func (fu Full) countSize() (meta any, err error) {
	var ter SumEr
	if meta, err = parDef.CallMethod(fu.Drive, fu.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = fu.sumEr(v); err != nil {
			return
		}
		if result, err = ter.Count(parDef.CtxBackground(parDef.GeneralReadMethodParameter(fu.Parameter1[k], ExternalCallAnyToInt64Func, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("rowsSize", err)
		return
	}
	return
}
func (fu Full) sumSize() (meta any, err error) {
	var ter SumEr
	if meta, err = parDef.CallMethod(fu.Drive, fu.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = fu.sumEr(v); err != nil {
			return
		}
		if result, err = ter.Sum(parDef.CtxBackground(parDef.GeneralReadMethodParameter(fu.Parameter1[k], ExternalCallAnyToInt64Func, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("sumSize", err)
		return
	}
	return
}
func (fu Full) dataSize() (meta any, err error) {
	var ter SumEr
	if meta, err = parDef.CallMethod(fu.Drive, fu.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = fu.sumEr(v); err != nil {
			return
		}
		if result, err = ter.DataSizeMB(parDef.CtxBackground(parDef.GeneralReadMethodParameter(fu.Parameter1[k], ExternalCallAnyToFloat64Func, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("dataSizeMB", err)
		return
	}
	return
}
func (fu Full) indexSize() (meta any, err error) {
	var ter SumEr
	if meta, err = parDef.CallMethod(fu.Drive, fu.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = fu.sumEr(v); err != nil {
			return
		}
		if result, err = ter.IndexSizeMB(parDef.CtxBackground(parDef.GeneralReadMethodParameter(fu.Parameter1[k], ExternalCallAnyToFloat64Func, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("indexSizeMB", err)
		return
	}
	return
}
func (fu Full) dataLSize() (meta any, err error) {
	var ter SumEr
	if meta, err = parDef.CallMethod(fu.Drive, fu.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = fu.sumEr(v); err != nil {
			return
		}
		if result, err = ter.DataLength(parDef.CtxBackground(parDef.GeneralReadMethodParameter(fu.Parameter1[k], ExternalCallAnyToFloat64Func, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("dataLSize", err)
		return
	}
	return
}
func (fu Full) avgRowsSize() (meta any, err error) {
	var ter SumEr
	if meta, err = parDef.CallMethod(fu.Drive, fu.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = fu.sumEr(v); err != nil {
			return
		}
		if result, err = ter.AvgRowsSize(parDef.CtxBackground(parDef.GeneralReadMethodParameter(fu.Parameter1[k], ExternalCallAnyToInt64Func, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("avgRowsSize", err)
		return
	}
	return
}
func (fu Full) GetFullRowsST() (result any, err error) {
	return fu.rowsSize()
}
func GetFullCountST(fu Full) (result any, err error) {
	return fu.countSize()
}
func (fu Full) GetFullSumST() (result any, err error) {
	return fu.sumSize()
}
func (fu Full) GetFullDataSizeST() (result any, err error) {
	return fu.dataSize()
}
func (fu Full) GetFullIndexSizeST() (result any, err error) {
	return fu.indexSize()
}
func (fu Full) GetFullDataLengthST() (result any, err error) {
	return fu.dataLSize()
}
func (fu Full) GetFullAvgRowsSizeST() (result any, err error) {
	return fu.avgRowsSize()
}
